﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Fashion.Models;

namespace Fashion.ViewModels
{
    public class StatisticsViewModel
    {
        public int newOrders { get; set; }
        public int newUsers { get; set; }
        public double totalSales { get; set; }
        public double totalProfit { get; set; }
        public DateTime date { get; set; }

        private FashionEntities1 FashionDB = new FashionEntities1();

        // Today's statistics
        public StatisticsViewModel()
        {
            var orders = from order in FashionDB.Orders
                         where order.OrderDate == DateTime.Today
                         select order;
            this.newOrders = orders.Count();

            double temp = 0;
            foreach (var item in orders)
            {
                temp = temp + item.TotalPrice;
            }
            this.totalSales = temp;
            this.totalProfit = this.totalSales * 0.05;

            var users = from user in FashionDB.Users
                        where user.RegisterDate == DateTime.Today
                        select user;
            this.newUsers = users.Count();
            this.date = DateTime.Today;
        }

        public StatisticsViewModel(DateTime date)
        {
            var orders = from order in FashionDB.Orders
                         where order.OrderDate == date
                         select order;
            this.newOrders = orders.Count();

            double temp = 0;
            foreach (var item in orders)
            {
                temp = temp + item.TotalPrice;
            }
            this.totalSales = temp;
            this.totalProfit = this.totalSales * 0.05;

            var users = from user in FashionDB.Users
                        where user.RegisterDate == date
                        select user;
            this.newUsers = users.Count();
            this.date = date;
        }
    }
}